<?php
require_once('line_item.php');
class Cart {
        var $items = array();
        var $total_price = 0.0;
        
        function items(){
                return $this->items;
        }               
        function add_product($product){
                //debug($product);
                $flg = false;
                for( $i = 0 ; $i < count($this->items) ; $i++){
                        $item = $this->items[$i];
                        if($item['product']['id'] == $product['id'] ){
                                //debug('BINGO');
                                $this->items[$i]['quantity'] += 1;
                                $flg = true;
                                //debug($this->items[$i]);
                                break;
                        }
                }
                if( $flg == false ){
                        $item = LineItem::for_product($product);
                        $this->items[] = $item;
                }
                //debug($flg);
                $this->total_price += $product['price'];
        }
		function do_empty(){
                $this->items = array();
                $this->total_price = 0.0;
        }
}
?>